/// 项目模型，定义项目数据的结构
class Project {
  final String id; // 项目 ID
  final int sequence; // 项目序号
  final String productCategory; // 产品分类
  final String sampleBatch; // 样品批量
  final String assemblyBOM; // 组装 BOM
  final String softwareStatus; // 软件状态
  final String zenLink; // 禅道链接
  final String softwareDetails; // 软件详情
  final String businessManager; // 业务负责人
  final String softwareManager; // 软件负责人
  final String projectManager; // 项目负责人
  final String testManager; // 测试负责人
  final int testTime; // 测试时间（小时）
  final int estimatedTime; // 预计时间（小时）
  final String? startTime; // 开始时间
  final String? completionTime; // 完成时间

  Project({
    required this.id,
    required this.sequence,
    required this.productCategory,
    required this.sampleBatch,
    required this.assemblyBOM,
    required this.softwareStatus,
    required this.zenLink,
    required this.softwareDetails,
    required this.businessManager,
    required this.softwareManager,
    required this.projectManager,
    required this.testManager,
    required this.testTime,
    required this.estimatedTime,
    this.startTime,
    this.completionTime,
  });

  /// 从 JSON 构造 Project 对象
  factory Project.fromJson(Map<String, dynamic> json) {
    return Project(
      id: json['_id']?.toString() ?? '',
      sequence: int.tryParse(json['序号']?.toString() ?? '0') ?? 0,
      productCategory: json['产品分类'] as String? ?? '未知',
      sampleBatch: json['样品批量'] as String? ?? '未知',
      assemblyBOM: json['组装BOM'] as String? ?? '',
      softwareStatus: json['软件状态'] as String? ?? '未知',
      zenLink: json['禅道链接软件版本及测试情况'] as String? ?? '',
      softwareDetails: json['软件情况'] as String? ?? '',
      businessManager: json['业务负责人'] as String? ?? '',
      softwareManager: json['软件负责人'] as String? ?? '',
      projectManager: json['项目负责人'] as String? ?? '',
      testManager: json['测试负责人'] as String? ?? '',
      testTime: int.tryParse(json['测试时间']?.toString() ?? '0') ?? 0,
      estimatedTime: int.tryParse(json['预计时间']?.toString() ?? '0') ?? 0,
      startTime: json['startTime'] as String?,
      completionTime: json['completionTime'] as String?,
    );
  }

  /// 转换为 JSON 格式
  Map<String, dynamic> toJson() {
    return {
      '序号': sequence,
      '产品分类': productCategory,
      '样品批量': sampleBatch,
      '组装BOM': assemblyBOM,
      '软件状态': softwareStatus,
      '禅道链接软件版本及测试情况': zenLink,
      '软件情况': softwareDetails,
      '业务负责人': businessManager,
      '软件负责人': softwareManager,
      '项目负责人': projectManager,
      '测试负责人': testManager,
      '测试时间': testTime,
      '预计时间': estimatedTime,
      'startTime': startTime,
      'completionTime': completionTime,
    };
  }
}
